package NLP;

import entity.Poem;
import util.JsonUtil4Poem;

import java.util.*;

/**
 * @author: ChenforCode
 * @date: 2018/12/29 14:58
 * @description: 跑完所有的诗歌文件，得到所有可能的平仄规则
 */
public class LevelAndOblique {
    public static void main(String[] args){
        JsonUtil4Poem util = new JsonUtil4Poem();
        List<Poem> poems = new ArrayList<Poem>();
        //得到所有诗的集合
        for (int i = 0; i < 58; i++){
            String filePath = "E:\\LiuChen\\IDEA Java\\GAPoemGenerator\\corpus\\simplified\\jueju\\" + i + ".json";
            poems.addAll(util.parse(filePath));
        }

        //用来盛放所有可能的平仄规则（set直接去重）
        Set<String> allPossibleLevel = new HashSet<String>();
        //对所有诗进行遍历，得到所有的平仄规则
        Iterator it = poems.iterator();
        while (it.hasNext()){
            Poem poem = (Poem) it.next();
            List<String> poemLevel = poem.getStrains();
            //只要四句平仄规则都有的
            if (poemLevel.size() == 2){
                //构造平仄字符串
                String level = poemLevel.get(0);
                level += poemLevel.get(1);
                //平仄规则必须为24个字符（包含四个标点）并且不含'○'和'？'这样含义不明的符号
                if (level.length() == 24 && !level.contains("○") && !level.contains("？")){
                    //抽出平仄，并根据平仄构造出0(平) 1(仄)字符串
                    String level_01 = "";
                    for (int i = 0; i < level.length(); i++){
                        if (i == 5 || i == 11 || i == 17 || i == 23){
                            continue;
                        }
                        if ('平' == level.charAt(i)){
                            level_01 += "0";
                        } else if ('仄' == level.charAt(i)){
                            level_01 += "1";
                        }
                    }
                    allPossibleLevel.add(level_01);
                }
            }
        }

        System.out.println(allPossibleLevel.size());
    }


}
